package org.caowei.samples.sevice;

import java.util.List;
import org.caowei.samples.dao.IExamTestDAO;
import org.caowei.samples.dao.ISubjectDAO;
import org.caowei.samples.model.ExamTest;
import org.caowei.samples.model.ExamTestTypeVO;
import org.caowei.samples.model.ExamTestVO;
import org.caowei.samples.model.Subject;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class ExamTestServiceImpl implements ExamTestService {

	@Autowired
	private IExamTestDAO IExamTestDAO;
	
	@Autowired
	private ISubjectDAO iSubjectDAO;
	

	@Override
	public List<ExamTest> findAllExamTests() {
		// TODO Auto-generated method stub
		return IExamTestDAO.findAllExamTests();
	}

	@Override
	public ExamTestVO getExamTestById(int id) {
		ExamTest entity = IExamTestDAO.getExamTestById(id);
		if (entity != null) {
			ExamTestVO vo = new ExamTestVO();
			BeanUtils.copyProperties(entity, vo);
			
			Subject subject = iSubjectDAO.get(entity.getSubId());
			if(subject != null){
				vo.setSubName(subject.getSubName());
			}
			ExamTestTypeVO typevo =new ExamTestTypeVO();
			BeanUtils.copyProperties(entity.getExamTestType(), typevo);
			vo.setExamTestType(typevo);
			
			return vo;
		}
		return null;
	}

	@Override
	public void createExamTest(ExamTest ExamTest) throws Exception {
		// TODO Auto-generated method stub
		IExamTestDAO.createExamTest(ExamTest);
	}

	@Override
	public void editExamTest(ExamTestVO ExamTestVO) throws Exception {
		ExamTest test = new ExamTest();
		BeanUtils.copyProperties(ExamTestVO, test);
		IExamTestDAO.editExamTest(test);
	}

	@Override
	public void deleteExamTest(int id) throws Exception {
		// TODO Auto-generated method stub
		IExamTestDAO.deleteExamTest(id);
	}

	@Override
	public List<ExamTest> findExamTestsBySubjectId(int subId) {
		// TODO Auto-generated method stub
		return IExamTestDAO.findExamTestBySubjectId(subId);
	}

}
